package com.example.gulimall.product.web;

import com.example.gulimall.product.entity.CategoryEntity;
import com.example.gulimall.product.service.CategoryService;
import com.example.gulimall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;
@Controller
public class IndexController {
    @Autowired
    CategoryService categoryService;
    @GetMapping({"/","index.html"})
    public String getIndex(Model model){
        List<CategoryEntity> categoryEntityList=categoryService.getLevel1Catagories();
        model.addAttribute("catagories",categoryEntityList);
        return "index";
    }
    @GetMapping("index/json/catalog.json")
    @ResponseBody
    public Map<String,List<Catelog2Vo>> getCategoryMap(){
        return categoryService.getCategoryMap();
    }
}
